<%--suppress ELValidationInJSP --%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%
    String path = request.getContextPath();
%>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="<%=path%>/plugins/layui/css/layui.css?version=1">
    <script src="<%=path %>/plugins/jquery.min.js" type="text/javascript"></script>
    <script src="<%=path%>/plugins/layui/layui.js"></script>
    <script type="text/javascript" src="<%=path%>/js/core/helper.js"></script>
</head>
<body align="center">


<div align="center" style="width: 400px;height: 200px">
    <img id="LAY_demo_upload" style="max-height:100%; max-width:100%;" src="<%=path%>/pic/upload_ioc.png"/>
</div>
<br>
<input type="hidden" id="filePath" name="filePath"/>
<input type="file" name="file" class="layui-upload-file" lay-title="添加一张图片">
<br>
<br>
<div align="center" style="width: 400px;">
    <button class="layui-btn layui-btn-primary layui-btn-small" onclick="cancel()">取消替换</button>
    <button class="layui-btn layui-btn-small" onclick="redistribution()">确定替换</button>
</div>

<script>
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    layui.use(['layer', 'form', 'upload'], function () {
        layui.upload({
            url: '<%=path%>/cms/resource/uploadFile.x?isTemp=' + true
            , success: function (res) {
                LAY_demo_upload.src = res.data.imageUrl;
                $('#filePath').val(res.data.imagePath);
            }
        });
    });

    function redistribution() {
        if ($("#filePath").val() == '') {
            parent.layer.alert("上传图片不能为空", {icon: 5});
            return false;
        }
        var param = {};
        param.resourceId = '${resourceId}';
        param.commCode = '${commCode}';
        param.fileName = '${fileName}';
        param.tempPath = $('#filePath').val();
        postJson("<%=path%>/cms/resource/redistributionOutdoorAdv.x", $.param(param), function (ret) {
            parent.queryCurrentResource();
            parent.layer.close(index);
        });
    }

    function cancel() {
        parent.layer.close(index);
    }
</script>

</body>
</html>